import java.util.Scanner;

public class Demo9 {
    public static int flag = 0;

    public static void main(String[] args) {
        Object locker = new Object();

        Thread t1 = new Thread(() -> {
            while (true) {
                synchronized (locker) {
                    if (flag != 0) {
                        break;
                    }
                }
            }
            System.out.println("循环结束");
        });
        Thread t2 = new Thread(() -> {
            Scanner scanner = new Scanner(System.in);
            System.out.println("输入一个整数");
            flag = scanner.nextInt();
        });
        t1.start();
        t2.start();
    }
}
